#pragma once

#include <string>
#include "FlowConfig.h"
#include "TinyThread.h"
#include "TinyMsg.h"
#include "v8.h"
#include "IVRNode.h"

using namespace TinyCC::msg;


namespace IVRFlow{
class CTalkFlow
{
public:
	CTalkFlow(void);
	virtual ~CTalkFlow(void);
	std::string TalkID;
	bool StartFlow(string talkId);
	std::string CallerID;
	std::string CalledID;
	bool readFlowFile(std::string filePath);
	CFlowConfig* flowConfig;
	void flowThreadFunc(void* param);
	TinyCC::CTinyThread *m_workThread;
	void TerminateFlow(void);
	void EndFlow(void);
	void ProcessReceivedMsg(CTinyMsg& inMsg,CTinyMsg& OutMsg);
	void ExecuteJScript(std::vector<string>& sourceCode);
	void FlowExceptioned(int errCode,std::string errMsg);
//public:
//	char m_talkIDStr[128];
private:
	void UpdateFlowVar(string key,CIVRNode * value);
	void UpdateFlowVar(string key, string value);
	void UpdateFlowVar(string key, int value);
	CIVRNode* GetFlowVar(string key);
private:
	std::vector<std::string> flow_Content;
	string m_talkID;
	std::map<string,CIVRNode*> varMap;
	std::vector<CIVRNode*> NodeVector;
	CIVRNode* m_currentNode;
};
}